package com.woniu.darryringmall.front.service.impl;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.darryringmall.front.entity.Order;
import com.woniu.darryringmall.front.entity.OrderItems;
import com.woniu.darryringmall.front.mapper.OrderItemsMapper;
import com.woniu.darryringmall.front.mapper.OrderMapper;
import com.woniu.darryringmall.front.service.OrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 订单表Service实现
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderItemsMapper orderItemsMapper;

    @Transactional
    @Override
    public void del(int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("orderid", id);
        orderItemsMapper.deleteByMap(map);
        orderMapper.deleteById(id);
    }


    public void update(@Param("id")int id, @Param("status")String status) {
        orderMapper.update(id,status);
    }

    //查找status为3的所有订单信息
    public List<Order> getByStatu3(int userid){
        return orderMapper.getByStatu3(userid);
    };

    //查找status为4的所有订单信息
    public List<Order> getByStatu4(int userid){
        return orderMapper.getByStatu4(userid);
    };

    //查找status为5的所有订单信息
    public List<Order> getByStatu5(int userid){
        return orderMapper.getByStatu5(userid);
    };

    //计算所有已完成订单的总金额（状态码7）
    public BigDecimal getMoney(int userid) {
        return orderMapper.getMoney(userid);
    };
}
